﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using Tuto.BLL;
using Tuto.Objects;
using Tuto.Tools;
using Npgsql;
namespace Brouillon
{
    class Program
    {
        static void Main(string[] args)
        {
            // Extrating the connexion string from the configuration file
            Hashtable dbConnexionConfig = (Hashtable)ConfigurationManager.GetSection("db_config/db_connexion");
            string conStr = String.Empty;

            conStr = String.Format
                (
                    "Server={0};" +
                    "Port={1};" +
                    "User={2};" +
                    "Password={3};" +
                    "Database={4};",
                    dbConnexionConfig["db_host"],
                    dbConnexionConfig["db_port"],
                    dbConnexionConfig["db_user"],
                    dbConnexionConfig["db_passwd"],
                    dbConnexionConfig["db_name"]
                );
            /* getting connected to the database
            Tuto.BLL.TutoEtudiant.instance.connexionString = conStr;
            Console.Out.WriteLine("ConStr = " + conStr);
            
            // Informations ...
            Console.Title = "Tuto Application GUI";
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.Out.WriteLine(" Manage a TutoEtudiant ");
            
            /*Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" First name : ");
            Console.ForegroundColor = ConsoleColor.White;
            string fname = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Last name : ");
            Console.ForegroundColor = ConsoleColor.White;
            string lname = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Adress : ");
            Console.ForegroundColor = ConsoleColor.White;
            string adress = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Email : ");
            Console.ForegroundColor = ConsoleColor.White;
            string email = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Phone : ");
            Console.ForegroundColor = ConsoleColor.White;
            string phone = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Carde number : ");
            Console.ForegroundColor = ConsoleColor.White;
            string cardNumber = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Diploma : ");
            Console.ForegroundColor = ConsoleColor.White;
            string diploma = Console.In.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.Write(" Level : ");
            Console.ForegroundColor = ConsoleColor.White;
            string level = Console.In.ReadLine();
            
            string fname = "Tidiane";
            string lname = "Sidibé";
            string adress = "Launay Violette";
            string email = "stidiovip@yahoo.fr";
            string phone = "2232333243";
            string cardNumber = "E109750T";
            string diploma = "MIAGE";
            string level = "M1";

            Regex checkEmail = new Regex(".*@.*..*");

            if (!checkEmail.IsMatch(email))
            {
                throw new Tuto.Tools.EmailException(email + " is not a valid email adress ");
            }
          
            Tuto.Objects.TutoEtudiant etudiant = new Tuto.Objects.TutoEtudiant
                (
                    fname, 
                    lname, 
                    adress, 
                    email, 
                    phone, 
                    cardNumber, 
                    diploma, 
                    level
                );
            int i = Tuto.BLL.TutoEtudiant.instance.add(fname, lname, adress, email, phone, cardNumber, diploma, level);
            if (i != 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Out.WriteLine(" {0} {1} has been added successfully ...", lname.ToUpper(), fname);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine(" Add failed ...");
            }
            Console.Out.WriteLine(" Presse Enter to Exit ...");
            string exitString = Console.In.ReadLine();*/
        }
    }
}
